﻿using Abp.Runtime.Validation;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JHT.ABPLearn.Tasks.Dto
{
    public class UpdateTaskInputDto : ICustomValidate
    {
        [Range(1, Int32.MaxValue)] //Data annotation attributes work as expected.
        public int Id { get; set; }

        public long? AssignedPersonId { get; set; }

        public TaskState? State { get; set; }

        [Required]
        public string Title { get; set; }

        [Required]
        public string Description { get; set; }

        public DateTime CreationTime { get; set; }

        /// <summary>
        /// 自定义错误信息
        /// </summary>
        /// <param name="context"></param>
        public void AddValidationErrors(CustomValidationContext context)
        {
            if (AssignedPersonId == null && State == null)
            {
                context.Results.Add(new ValidationResult("任务关联人和任务状态不能为空", new string[] { "AssignedPersonId", "State" }));
            }
        }

        /// <summary>
        /// 重写tostring 方法  方便在调试或打日志时看到相关的类状态
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("[UpdateTaskInput > TaskId = {0}, AssignedPersonId = {1}, State = {2}]", Id, AssignedPersonId, State);
        }

    }
}
